package com.source.barcodeMachineGrantAndRecovery.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.source.barcodeMachineGrantAndRecovery.VO.HouseMachineVO;
import com.source.barcodeMachineGrantAndRecovery.entity.HouseMachine;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.source.baseData.entity.BarcodeMachine;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author IceBerg777
 * @since 2021-03-27
 */
@Repository
public interface HouseMachineMapper extends BaseMapper<HouseMachine> {

    String SELECT = "SELECT hm.*, slaughterHouseName houseName, su.`name` grantPersonName, ss.`name` receivePersonName    \n" +
            "FROM house_machine hm , slaughter_house sh, sys_user su, sys_user ss  \n" +
            "WHERE hm.houseId = sh.slaughterHouseId AND su.userId = grantPersonId AND ss.userId = receivePersonId  " +
            "AND hm.isDelete = 0 AND sh.isDelete = 0 AND su.isDelete = 0 AND ss.isDelete = 0  ";

    @Select(SELECT)
    List<HouseMachineVO> findList();

    @Select(SELECT)
    IPage<HouseMachineVO> findPages(Page<Object> objectPage);

    @Select(SELECT + "AND concat_ws(',' , machineNumber ,slaughterHouseName, su.`name`, ss.`name`, price, productDate) LIKE #{keyWord}")
    IPage<HouseMachineVO> findSimilar(String keyWord, Page<Object> objectPage);

    @Select("SELECT * FROM barcode_machine bm WHERE bm.barcodeMachineNumber NOT IN (SELECT machineNumber FROM house_machine)")
    List<BarcodeMachine> findUnSaved();
}
